package com.webmarmun.baza;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class SingleView extends Activity {
	static String imeTumaca;
	static SitesList sitesList = MyXMLHandler.sitesList;

	
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.mainsingle);
		showResults() ;


		

	}

	public void showResults() {
		
		
	   
		Bundle bundle = this.getIntent().getExtras();
		String param1 = bundle.getString("param");
		TableLayout  layout = (TableLayout) findViewById(R.id.linear);
		layout.setOrientation(1);

		//TextView name[] = null;
		TextView adresa[] = null;
		TextView jezik[] = null;
		
		 
		
		//name = new TextView[sitesList.getIme().size()];
		adresa = new TextView[sitesList.getIme().size()];
		jezik = new TextView[sitesList.getIme().size()];
		
		
		/** Set the result text in textview and add it to layout */
		for (int i = 0; i < sitesList.getAdresa().size(); i++) {
			TableRow tr = new TableRow(this);
			
			

			jezik[i] = new TextView(this);
			jezik[i].setText(sitesList.getJezik().get(i));
			if (jezik[i].getText().toString().equals(param1)) {
				//name[i] = new TextView(this);

				//name[i].setText(sitesList.getPrezime().get(i) + " "
				//		+ sitesList.getIme().get(i));
//				name[i].setTextSize(23);
//				name[i].setHeight(23);
//				name[i].setId(i);
//				name[i].setClickable(true);
//				name[i].setTextColor(Color.WHITE);
//				name[i].setClickable(true);
				final String ime = sitesList.getPrezime().get(i) + " "
						+ sitesList.getIme().get(i).toString()+"\n"+sitesList.getAdresa().get(i);
                
				adresa[i] = new TextView(this);
				adresa[i].setText(sitesList.getAdresa().get(i));
				adresa[i].setHeight(20);
				adresa[i].setTextColor(Color.WHITE);
				
//				name[i].setOnClickListener(new OnClickListener() {
//
//					public void onClick(View view) {
//						Clicked(ime);
//
//					}
//				});
				Button btn = new Button(this);
				btn.setBackgroundResource(R.drawable.infoicon);
				
				btn.setText(ime);
				
				
				
				 
				btn.setOnClickListener(new OnClickListener() {
		 
					@Override
					public void onClick(View arg0) {
		 
						Clicked(ime);
		 
					}
		 
				});
				
                
                
                
				

				
				//tr.addView(name[i]);
				
				
				tr.addView(btn);
				//tr.addView(adresa[i]);

//				layout.addView(name[i]);
//				layout.addView(btn1[i]);
//				layout.addView(adresa[i]);

			}
			layout.addView(tr);


			ScrollView svh = (ScrollView) findViewById(R.id.scroll2);
			svh.removeAllViews();
			svh.addView(layout);

			setContentView(svh);

		}

	}

	public void Clicked(String ime) {
		Bundle bundle2 = new Bundle();
		bundle2.putString("imeIzabranogTumaca", ime);
		Intent in = new Intent(this.getApplicationContext(), InfoView.class);
		in.putExtras(bundle2);
		SingleView.this.startActivityForResult(in, 0);
	}

}
